package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.CompanyMotto;
import com.prs.crm.service.sys.CompanyMottoService;

public class CompanyMottoAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private CompanyMotto companyMotto;
	private CompanyMottoService companyMottoService;
	private String sercode;//共用查询编码
	public CompanyMotto getCompanyMotto() {
		return companyMotto;
	}
	public void setCompanyMotto(CompanyMotto companyMotto) {
		this.companyMotto = companyMotto;
	}
	public CompanyMottoService getCompanyMottoService() {
		return companyMottoService;
	}
	public void setCompanyMottoService(CompanyMottoService companyMottoService) {
		this.companyMottoService = companyMottoService;
	}
	@Action("viewCompanyMotto")
	public String viewCompanyMotto(){
		System.out.println("sercode:"+sercode);
		this.companyMotto=this.getCompanyMottoService().getCompany(sercode);
		return SUCCESS;
	}
	
	@Action(value="saveCompanyMotto",results={
			@Result(name="success",type="redirect",location="viewCompanyMotto?sercode=${companyMotto.getType()}"),
			@Result(name="error",type="chain",location="viewCompanyMotto?sercode=${companyMotto.getType()}")
	})
	public String saveCompanyMotto(){
//		if(companyMotto.getName()==null){
			CompanyMotto comp=this.getCompanyMottoService().getCompany("Jx01");
			if(comp==null)
			{
				comp=new CompanyMotto();
				comp.setType("Jx01");
				comp.setName(companyMotto.getName());
				this.getCompanyMottoService().save(comp);
			}else{
				comp.setName(companyMotto.getName());
				this.getCompanyMottoService().submit(comp);
			}			
			companyMotto=comp;		
			return SUCCESS;
//		}
//		else{
//			CompanyMotto comp=this.getCompanyMottoService().getCompany("Jx01");
//			this.getCompanyMottoService().submit(companyMotto);
//			return SUCCESS;
//		}	
	}
	public String getSercode() {
		return sercode;
	}
	public void setSercode(String sercode) {
		this.sercode = sercode;
	}
	
}
